<?php

namespace app\admin\app\model;

use Qiniu\Auth;
use Qiniu\Storage\BucketManager;
use Qiniu\Storage\UploadManager;

class Qiniu
{
    protected $qiniu;

    function __construct($config = [])
    {
        $this->qiniu = new Auth('-nYPTkUjszQQQjzpxPR69J-kuhlYC6CxbLto1-L4', 'JU_mdCWPtWyRpcoKIwSBA8tQYgudR3eRn9rZpawB');
    }

    public function token($bucket = 'zte001')
    {
        return $this->qiniu->uploadToken($bucket);
    }

    public function upload($file, $bucket = 'zte001')
    {
        $upload = new UploadManager();
        return $upload->putFile($this->token($bucket), null, $file);
    }

    public function uploadDouyin($file, $bucket = 'zte001')
    {
        $upload = new UploadManager();
        return $upload->put($this->token($bucket), null, $file);
    }

    public function delete($key, $bucket = 'zte001')
    {
        $bucketMgr = new BucketManager($this->qiniu);
        return $bucketMgr->delete($bucket, $key);
    }
}